﻿$(document).ready(function () {
    $("#uid, #pwd, #code").focus(function () {
        $(this).addClass("focus");
    }).blur(function () {
        $(this).removeClass("focus");
    });
    if ($.browser.msie && parseInt($.browser.version) < 7) {
        $("#top").css("background-position", "0").animate({ height: '+=25' }, 800);
    }
    $('#loginbtn').click(function () {
        if ($('#uid').val() == '' || $('#pwd').val() == '') {
            $('#remind').css('color', 'red').html('<img src="images/icons/warn.png" alt="" /> 请输入用户名或密码！');
            return false;
        } else if ($('#code').val() == '') {
            $('#remind').css('color', 'red').html('<img src="images/icons/warn.png" alt="" /> 请输入验证码！');
            return false;
        } else {
            $.ajax({
                type: "post",
                url: "/Tools/DoAction.ashx",
                data: "act=login&u=" + $("#uid").val() + "&p=" + $("#pwd").val() + "&c=" + $("#code").val(),
                beforeSend: function () { $("#msg").html('<img src="/images/loading.gif" alt="" />'); },
                success: function (msg) {
                    if (msg == "1") {
                        $("#msg").html('<img src="/images/icons/error.png" alt="" />');
                        $("#code").focus();
                    } else if (msg == "2") {
                        $("#msg").html('');
                        $("#code").val('');
                        $('#valiCode').attr("src", "Tools/VerifyCode.ashx?size=5&id=" + parseInt(Math.random() * 10000));
                        $("#remind").css('color', 'red').html('<img src="images/icons/warn.png" alt="" /> 用户名不存在或密码错误！');
                    } else {
                        location.href = '/';
                    }
                },
                error: function () { $.dialog({ content: '网络繁忙！', icon: 'error' }); }
            })
        }
    })
    $('#valiCode').click(function () { $(this).attr("src", "Tools/VerifyCode.ashx?size=5&id=" + parseInt(Math.random() * 10000)); })
    $('#home').click(function () { homefav.Homepage(); })
    $('#jrsc').click(function () { homefav.Favorite(); })
    $("#uid").focus();
    $("#code").focus(function () { $(this).select(); });
    $(document).bind('contextmenu', function (e) { return false; });
})
window.onload = function () { $('#valiCode').click(); }